<?php
$loader->requireOnce('includes/PickDM/PickDMModel.class.php');
/**
 *
 * @package modules.dept_pharmacy.includes.PickDM
 * @author viethd
 * @version $Id$
 * @copyright 2009 LHV Company
 */
class PickDMModelBuilder{

    private $exticketId;
    private $pickDMModel = array();

    function __construct($exticketId) {   
        $this->exticketId =    $exticketId; 
    }
    /**
     * 
     * @author hdviet
     *
     * @param $data['pha_ewh_exticket_id','pha_drug_material_id',
     * 'req_quantity',
     * 'approve_quantity',
     * 'note',
     * 'pha_req_exticket_detail_id',
     * 'pha_ewh_imticket_id',
     * 'quantity'->picked quantity]
     * every record item in $data contain data of picking drug for a detail request
     * @return unknown_type
     */

    public function addModelData($data = array()) {
        
        if (!isset($this->pickDMModel[$data['pha_req_exticket_detail_id']])) {
            $model = new PickDMModel(
            $data['pha_ewh_exticket_id'],
            $data['pha_drug_material_id'],
            $data['req_quantity'],
            $data['approve_quantity'],
            $data['note'],
            $data['pha_req_exticket_detail_id']           
            );
           
            $this->pickDMModel[$data['pha_req_exticket_detail_id']] = $model;
        }
        
        
    }
    
    public function addDetailPicking($phaReqExticketDetailId, 
                $phaEwhImticketDetailId,
                $appQuantity) {        
        if (isset($this->pickDMModel[$phaReqExticketDetailId])) {
            $model = &$this->pickDMModel[$phaReqExticketDetailId];            
            //add pick drug detail into model
            $model->addPickingDetail($phaEwhImticketDetailId, $appQuantity);
        } else {
            //TODO log file this $phaReqExticketDetailId
           
        }        
    }
    public function save() {
        foreach ($this->pickDMModel as &$item) {
        	$item->save();
        }
        
    }


}
?>